package com.kgc.controller;

import com.kgc.common.Result;
import com.kgc.entity.Notifications;
import com.kgc.service.interf.NotificationsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;


// 网站公告模块
@Controller
@RequestMapping("/apis/notifications")
public class NotificationsController {
    @Autowired
    private NotificationsService notificationsService;

//    查看公告
    @RequestMapping("/selectnotifications")
    public String selectnotifications(Notifications notificationID){
        List<Notifications> notifications = notificationsService.selectNotifications(notificationID);
        if (notifications!=null){
            return Result.success("200","查询公告成功",notifications);
        }else {
            return Result.success("200","查询公告失败");
        }
    }

//    发布公告
    @RequestMapping("/addnotifications")
    public String addnotifications(Notifications notifications){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ");
        notifications.setCreatedAt(simpleDateFormat.format(new Date()));
        int i = notificationsService.addNotifications(notifications);
        if (i>0){
            return Result.success("200","发布成功");
        }else {
            return Result.success("400","发布失败");
        }
    }

//   删除公告
@RequestMapping("/delnotifications")
public String delnotifications(Notifications notifications){
    int i = notificationsService.deleteNotifications(notifications);
    if (i>0){
        return Result.success("200","删除成功");
    }else {
        return Result.success("400","删除失败");
    }
}




}
